package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/order")
@RestController
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 下单
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public R<String>submit(@RequestBody Orders orders){
        log.info("订单数据:{}",orders);
        orderService.submit(orders);
        return R.success("下单成功");
    }

    /**
     * 查询历史订单
     * @param page
     * @param pageSize
     * @return
     *
     */
    @GetMapping("/userpage")
    public R<Page>oderpage(int page,int pageSize){
        Orders orders=new Orders();
        String number = orders.getNumber();//订单号
        Page pageInfo =orderService.oderPage(page,pageSize,number);
        return R.success(pageInfo);
    }

    /**
     * 订单明细
     * @param page
     * @param pageSize
     * @param number
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping("/page")
    public R<Page>orderDetail(int page,int pageSize,String number,String beginTime,String endTime){
       Page pages= orderService.orderDetail(page,pageSize,number,beginTime,endTime);
       return R.success(pages);
    }

}
